package com.wsdk.util;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.wsdk.R;
import com.wsdk.Wsdk;

/**
 * @author fionera
 */
public class ShowToast {
    private static Toast toast;
    private static TextView tvText;

    @SuppressLint("ShowToast")
    public static void shortTime(String text) {
        if (Wsdk.getInstance() == null) {
            return;
        }
        if (TextUtils.isEmpty(text)) {
            return;
        }
        if (toast == null) {
            View view = View.inflate(Wsdk.getInstance(), R.layout.layout_toast_body, null);
            tvText = view.findViewById(R.id.tv_toast);
            tvText.setText(String.valueOf(text));
            toast = Toast.makeText(Wsdk.getInstance(), String.valueOf(text),
                    Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.BOTTOM, 0, DisplayUtil.dp2px(120));
            toast.setView(view);
        } else {
            tvText.setText(String.valueOf(text));
        }
        toast.show();
    }
}
